package com.example.ch3;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Servlet implementation class BeerSelectWithJSP
 */
public class BeerSelectWithJSP extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BeerSelectWithJSP() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		String colorSelected = request.getParameter("color");
		List<String> brands = new BeerExpert().getBrands(colorSelected);
		RequestDispatcher dispatcher = request.getRequestDispatcher("beerJSP.jsp");
		request.setAttribute("brands", brands);
		dispatcher.forward(request, response);
	}

}
